This allows tests to be built, but not run.
sh tests/check-style.sh
no-exes:
- find $$(git ls-files) -perm +111 -type f \
+ find $$(git ls-files | grep -v ttf) -perm +111 -type f \
-not -name configure -not -name '*.sh' -not -name '*.rs' | \
grep '.*' \
&& exit 1 || exit 0
Options:
-h, --help Print this message
+ --no-run Compile, but don't run benchmarks
-j N, --jobs N The number of jobs to run in parallel
+ --target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build benchmarks for
-v, --verbose Use verbose output
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
shell.set_verbose(options.flag_verbose);
- let mut compile_opts = ops::CompileOptions {
- update: false,
- env: "bench",
- shell: shell,
- jobs: options.flag_jobs,
- target: None,
- dev_deps: true,
+ let mut ops = ops::TestOptions {
+ no_run: options.flag_no_run,
+ compile_opts: ops::CompileOptions {
+ update: false,
+ env: "bench",
+ shell: shell,
+ jobs: options.flag_jobs,
+ target: options.flag_target.as_ref().map(|s| s.as_slice()),
+ dev_deps: true,
+ },
};
- let err = try!(ops::run_benches(&root, &mut compile_opts,
+ let err = try!(ops::run_benches(&root, &mut ops,
options.arg_args.as_slice()).map_err(|err| {
CliError::from_boxed(err, 101)
}));
Options:
-h, --help Print this message
+ --no-run Compile, but don't run tests
-j N, --jobs N The number of jobs to run in parallel
--target TRIPLE Build for the target triple
-u, --update-remotes Deprecated option, use `cargo update` instead
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
shell.set_verbose(options.flag_verbose);
- let mut compile_opts = ops::CompileOptions {
- update: options.flag_update_remotes,
- env: "test",
- shell: shell,
- jobs: options.flag_jobs,
- target: options.flag_target.as_ref().map(|s| s.as_slice()),
- dev_deps: true,
+ let mut ops = ops::TestOptions {
+ no_run: options.flag_no_run,
+ compile_opts: ops::CompileOptions {
+ update: options.flag_update_remotes,
+ env: "test",
+ shell: shell,
+ jobs: options.flag_jobs,
+ target: options.flag_target.as_ref().map(|s| s.as_slice()),
+ dev_deps: true,
+ },
};
- let err = try!(ops::run_tests(&root, &mut compile_opts,
+ let err = try!(ops::run_tests(&root, &mut ops,
options.arg_args.as_slice()).map_err(|err| {
CliError::from_boxed(err, 101)
}));
use ops;
use util::{CargoResult, ProcessError};
+pub struct TestOptions<'a> {
+ pub compile_opts: ops::CompileOptions<'a>,
+ pub no_run: bool,
+}
+
pub fn run_tests(manifest_path: &Path,
- options: &mut ops::CompileOptions,
- args: &[String]) -> CargoResult<Option<ProcessError>> {
+ options: &mut TestOptions,
+ test_args: &[String]) -> CargoResult<Option<ProcessError>> {
let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(source.update());
let package = try!(source.get_root_package());
- let mut compile = try!(ops::compile(manifest_path, options));
+ let mut compile = try!(ops::compile(manifest_path, &mut options.compile_opts));
+ if options.no_run { return Ok(None) }
compile.tests.sort();
let cwd = os::getcwd();
Some(path) => path,
None => exe.clone(),
};
- let cmd = compile.process(exe, &package).args(args);
- try!(options.shell.concise(|shell| {
+ let cmd = compile.process(exe, &package).args(test_args);
+ try!(options.compile_opts.shell.concise(|shell| {
shell.status("Running", to_display.display().to_string())
}));
- try!(options.shell.verbose(|shell| {
+ try!(options.compile_opts.shell.verbose(|shell| {
shell.status("Running", cmd.to_string())
}));
match cmd.exec() {
});
for (lib, name) in libs {
- try!(options.shell.status("Doc-tests", name));
+ try!(options.compile_opts.shell.status("Doc-tests", name));
let mut p = compile.process("rustdoc", &package)
.arg("--test").arg(lib)
.arg("--crate-name").arg(name)
.cwd(package.get_root());
// FIXME(rust-lang/rust#16272): this should just always be passed.
- if args.len() > 0 {
- p = p.arg("--test-args").arg(args.connect(" "));
+ if test_args.len() > 0 {
+ p = p.arg("--test-args").arg(test_args.connect(" "));
}
for (pkg, libs) in compile.libraries.iter() {
}
}
- try!(options.shell.verbose(|shell| {
+ try!(options.compile_opts.shell.verbose(|shell| {
shell.status("Running", p.to_string())
}));
match p.exec() {
}
pub fn run_benches(manifest_path: &Path,
- options: &mut ops::CompileOptions,
+ options: &mut TestOptions,
args: &[String]) -> CargoResult<Option<ProcessError>> {
let mut args = args.to_vec();
args.push("--bench".to_string());
pub use self::cargo_doc::{doc, DocOptions};
pub use self::cargo_generate_lockfile::{generate_lockfile, write_resolve};
pub use self::cargo_generate_lockfile::{update_lockfile, load_lockfile};
-pub use self::cargo_test::{run_tests, run_benches};
+pub use self::cargo_test::{run_tests, run_benches, TestOptions};
mod cargo_clean;
mod cargo_compile;
fresh = FRESH,
dir = p.url()).as_slice()));
})
+
+test!(test_no_run {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "
+ #[test]
+ fn foo() { fail!() }
+ ");
+
+ assert_that(p.cargo_process("cargo-test").arg("--no-run"),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} foo v0.0.1 ({dir})
+",
+ compiling = COMPILING,
+ dir = p.url()).as_slice()));
+})